import { Axios } from '@axios/base'
import { HttpStatus } from '@axios/base/http_status';
import { User } from '@entity/user';
import { SimpleEntity } from '@entity/common';
import { WebSocketRequest } from '@entity/ws';
import { AddFriendRequest, AddFriendResponse } from '@entity/add_user';

export class WebSocketAddFriend extends Axios {

    constructor() {
        super('ws/friend');
    }

    /**
     * POST /ws/friend/request
     * 发送好友申请
     * @param receiver 接收方
     * @param data 请求数据
     */
    async request(receiver: User | SimpleEntity, data: AddFriendRequest): Promise<Boolean> {
        let request: WebSocketRequest<AddFriendRequest> = new WebSocketRequest(receiver, data);
        const result = await this.post<Boolean>('/request', request);
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

    /**
     * POST /ws/friend/response
     * 响应好友申请
     * @param receiver 接收方
     * @param data 响应数据
     */
    async response(receiver: User | SimpleEntity, data: AddFriendResponse): Promise<Boolean> {
        let response: WebSocketRequest<AddFriendResponse> = new WebSocketRequest(receiver, data);
        const result = await this.post<Boolean>('/response', response);
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

}